package com.kitty.game.utils;

import com.kitty.mina.codec.IMessageEncoder;
import com.kitty.mina.codec.SerializerHelper;
import com.kitty.mina.message.Message;

import java.text.DecimalFormat;

public class AsktaoUtil {
    public static long serverStartTime = 8658970;

    public static String getFormatTao(long taoPoint) {
        StringBuilder result = new StringBuilder("#R");
        long year = taoPoint / Const.ONE_YEAR_POINT;
        long day = (taoPoint % Const.ONE_YEAR_POINT) / Const.ONE_DAY_POINT;
        long point = taoPoint % Const.ONE_DAY_POINT;
        if (year >= 1) {
            result.append(year).append("#n年#R");
        }
        if (day >= 1) {
            result.append(day).append("#n天#R");
        }
        if(point>=1){
            result.append(point).append("#n点");
        }
        result.append("#n");

        return result.toString();
    }

    public static String getMoneyFormat(int needMoney) {
        DecimalFormat decimalFormat = new DecimalFormat("#,###");
        String msg = decimalFormat.format(needMoney);
        String color;
        if (msg.length() >= 12) {
            color = "#c009ACD";
        } else {
            if (msg.length() >= 11) {
                color = "#cEE2C2C";
            } else {
                if (msg.length() >= 10) {
                    color = "#cFFFF00";
                } else {
                    if (msg.length() >= 9) {
                        color = "#cBA55DC";
                    } else {
                        if (msg.length() >= 7) {
                            color = "#c32CD32";
                        } else {
                            color = "#c6D76B2";
                        }
                    }
                }
            }
        }
        return color + msg + "#n";
    }

    /**
     * 取Message 字节集
     */
    public static byte[] getMessageBody(Message message) {
        IMessageEncoder msgEncoder = SerializerHelper.getInstance().getEncoder();
        return msgEncoder.writeMessageBody(message);
    }
}
